package com.project.service.impl;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.project.bean.ContractBean;
import com.project.bean.PageBean;
import com.project.dao.ContractMapper;
import com.project.service.IContractService;

@Service(value = "contractService")
public class ContractServiceImpl implements IContractService{
	@Autowired
	private ContractMapper mapper;

	@Override
	public void addContract(ContractBean contract) {
		mapper.insert(contract);
		
	}

	@Override
	public void ChangeContractState(ContractBean contract) {
		mapper.updateByPrimaryKeySelective(contract);
		
	}

	@Override
	public PageBean findContractByStateAndPage(Integer state, Integer UId, Integer size, Integer page) {
		PageBean pageBean = new PageBean();
		pageBean.setSize(size);
		pageBean.setPage(page);
		int totalNumber = mapper.countByState(state, UId);
		pageBean.setTotalNumber(totalNumber);
		pageBean.setTotalPage(totalNumber/size);
		int start = size*(page-1);
		pageBean.setList(mapper.selectByStateAndPage(state, UId, start, size)); 
		return pageBean;

	}

	@Override
	public ContractBean findContractByCtId(Integer ctId) {
		return mapper.selectByPrimaryKey(ctId);
	}



}
